/**
 * @class Admin
 */ 
var Admin = Class.create(AjaxClient,
{
  perms: [],

  /**
   * initialize
   */
  initialize: function()
  {
    this.setServer('admin.ajaxsrv.php');

//    $('div_infos_compte', 'div_change_pwd').invoke('hide');
    $('div_infos_user').hide();

    this.wndUser = new Window( { maximizable : false } );
    this.wndUser.setContent('div_infos_user', true, false);

    this.registerCallbacks();
    
    this.ajaxUpdate('users', { action: 'get_users' });
  },
  
  /**
   * registerCallbacks
   */
  registerCallbacks: function()
  {
    Event.observe('btn_creer_user', 'click', function(event)
    {
      this.showWndUser('Nouvel utilisateur', 'create_user', '', '', '', 'Créer');
      Event.stop(event);
    }.bind(this));
  },
 
  /**
   * set_perms
   */
  set_perms: function(perms)
  {
    this.perms = perms.split(',');
  },

  /**
   * showWndUser
   */
  showWndUser: function(title, action, uid, login, name, perms, btnLabel)
  {
    var params = $H({ user_action : action
                    , user_id     : uid
                    , user_login  : login
                    , user_name   : name
                    , user_perms  : perms
                    , user_btn    : btnLabel
                    });
    params.each(function(pair) { Form.Element.setValue(pair.key, pair.value); });

    this.wndUser.setTitle(title);
    this.wndUser.showCenter(true);
    Form.Element.focus('user_login');
  },
  
  /**
   * hideWndUser
   */
  hideWndUser: function()
  {
    this.wndUser.hide();
  },
  
  /**
   * look_compte
   */     
  look_user: function(uid, login, name, perms)
  {
    var id_row      = 'row_user_' + uid;

    new Event.Over(id_row);

    Event.observe(id_row, 'click', function(event)
    {
      this.showWndUser("Mise à jour d'un utilisateur", 'update_user', uid, login, name, perms, 'Mettre à jour');
    }.bind(this));
  }
});

Event.observe(window, "load", function(event)
{
  window.Admin = new Admin();
});
